/**  
 * Copyright © 2019. All rights reserved.
 * @Title: SendMessageUtil.java
 * @Prject: Message-Login-Redis-MQ
 * @Package: com.bw
 * @Description: 
 * @author: 云_1707A_敬乾超
 * @date: 2019年11月19日 下午8:22:57
 * @version: V1.0  
 */
 
package com.tensquare.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;


/**@Title: SendMessageUtil.java
 * @Description: 
 */

public class SendMessageUtil {
	
	public static String sendMessage(String tel,String yzm,String tplid) {
		 String return_code = "";
		 String host = "http://dingxin.market.alicloudapi.com";
		    String path = "/dx/sendSms";
		    String method = "POST";
		    String appcode = "a63066a8df8f4efda440d11fa654bf59";
		    Map<String, String> headers = new HashMap<String, String>();
		    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
		    headers.put("Authorization", "APPCODE " + "a63066a8df8f4efda440d11fa654bf59");
		    Map<String, String> querys = new HashMap<String, String>();
		    querys.put("mobile", tel);
		    querys.put("param", "code:"+yzm);
		    querys.put("tpl_id", "TP1711063");
		    Map<String, String> bodys = new HashMap<String, String>();
		    try {
		    	/**
		    	* 重要提示如下:
		    	* HttpUtils请从
		    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
		    	* 下载
		    	*
		    	* 相应的依赖请参照
		    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
		    	*/
		    	HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
		    	System.out.println(response.toString());
		    	//获取response的body
		    	return_code = EntityUtils.toString(response.getEntity());
		    } catch (Exception e) {
		    	e.printStackTrace();
		    }
			return return_code;
	}

}


